var app = getApp();
Page(Object.assign({},{
    data:{
        curPage : '/zofui_sales/pages/user/user',
        order: [{
            text: "待付款",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-fu.png",
            icona : "https://img11.360buyimg.com/ddimg/jfs/t1/31313/27/12380/2746/5cb72c40E788d5295/0712d7835e8ca3a7.png",
            num: 0,
            url: "/zofui_sales/order/orderlist?status=1",
            key : 'waitpay',
        }, {
            text: "已付款",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-use.png",
            icona : "https://img11.360buyimg.com/ddimg/jfs/t1/37628/32/2952/3519/5cb72c35E5b4efdf1/04788e1f9e544d65.png",
            num: 0,
            url: "/zofui_sales/order/orderlist?status=2",
            key : 'waitsend',
        }, {
            text: "待完成",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-jianjia.png",
            icona : "https://img11.360buyimg.com/ddimg/jfs/t1/37103/1/1609/2106/5cb72c45E0a79794c/642f456358179607.png",
            num: 0,
            url: "/zofui_sales/order/orderlist?status=3",
            key : 'sended',
        }, {
            text: "待评价",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-pingjia.png",
            icona : "https://img11.360buyimg.com/ddimg/jfs/t1/34845/34/3031/1649/5cb72c3bE2927dac5/dfe5b887b421237a.png",
            num: 0,
            url: "/zofui_sales/order/orderlist?status=4",
            key : 'waitdis',
        }],
        func: {collect:{
            text: "我的收藏",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-like.png",
            isshow: 1,
            url: "/zofui_sales/user/collect",
            type: "url",
            num: 0
        }, cut:{
            name : '',
            text: "减价活动",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-act_jian.png",
            isshow: 1,
            url: "/zofui_sales/cut/mylist",
            type: "url",
            num: 0
        }, group:{
            name : '',
            text: "拼单活动",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-pintuan.png",
            isshow: 1,
            url: "/zofui_sales/group/mylist",
            type: "url",
            num: 0
        },share:{
            name : '',
            text: "我的推广",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-tuiguan.png",
            isshow: 1,
            url: "/zofui_sales/fenxiao/user",
            type: "url",
            num: 0
        },card:{
            name : '',
            text: "优惠券",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-youhui.png",
            isshow: 1,
            url: "/zofui_sales/card/mylist",
            type: "url",
            num: 0
        },redbag:{
            name : '',
            text: "我的红包",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-hong.png",
            isshow: 1,
            url: "/zofui_sales/redbag/mylist",
            type: "url",
            num: 0
        },shop:{
            name : '',
            text: "商户后台",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/82800/31/6507/6992/5d47a2b4Ee8400fde/00ad26fb79b5e6a9.png",
            isshow: 1,
            url: "/zofui_sales/admin/login",
            type: "url",
            num: 0
        },jifen:{
            name : '',
            text: "中心",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/80257/5/6471/7243/5d47a26dE92afc3a1/e6c17589314485bc.png",
            isshow: 1,
            url: "/zofui_sales/jifen/index",
            type: "url",
            num: 0
        },agent:{
            name : '',
            text: "合伙人中心",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/51524/37/6863/7519/5d47a22eE29475270/5ca9f2da337b8ea2.png",
            isshow: 1,
            url: "/zofui_sales/agent/index",
            type: "url",
            num: 0
        },fenc:{
            name : '',
            text: "购物分成",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/65800/6/6456/5445/5d47a253E3eb14620/b463c4e776c9279d.png",
            isshow: 1,
            url: "/zofui_sales/fenchen/index",
            type: "url",
            num: 0
        },cityl:{
            name : '',
            text: "区域代理",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/51524/37/6863/7519/5d47a22eE29475270/5ca9f2da337b8ea2.png",
            isshow: 1,
            url: "/zofui_sales/ctagent/index",
            type: "url",
            num: 0
        },ctyagent:{
            name : '',
            text: "城市代理",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/51524/37/6863/7519/5d47a22eE29475270/5ca9f2da337b8ea2.png",
            isshow: 0,
            url: "/zofui_sales/ctyagent/index",
            type: "url",
            num: 0
        },sign:{
            name : '',
            text: "到店签到",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/70734/34/6433/4318/5d47a285E9de353a0/97ea5bb0b445e10b.png",
            isshow: 1,
            url: "/zofui_sales/sign/mysign",
            type: "url",
            num: 0
        },daysign:{
            name : '',
            text: "每日签到",
            icon: "http://img11.360buyimg.com/ddimg/jfs/t1/91845/28/9698/8888/5e1340bcE983101aa/6add4eb487ae1c16.png",
            isshow: 0,
            url: "/zofui_sales/daysign/index",
            type: "url",
            num: 0
        },jizi:{
            name : '',
            text: "我的集字",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/58140/19/751/6069/5ce8b03bE5aa3268f/3874dd6aa98e5247.png",
            isshow: 1,
            url: "/zofui_sales/jizi/index?status=3",
            type: "url",
            num: 0
        },yhm:{
            name : '',
            text: "优惠码",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/53991/4/4472/4802/5d22a396Eae5e7835/07bc4d10c6118744.png",
            isshow: 0,
            url: "/zofui_sales/yhm/index",
            type: "url",
            num: 0
        },quest:{
            name : '',
            text: "我的问答",
            icon: "http://img11.360buyimg.com/ddimg/jfs/t1/47584/39/15360/10578/5dc57f50Eb039ac78/228ec328f5949820.png",
            isshow: 0,
            url: "/zofui_sales/quest/mylist",
            type: "url",
            num: 0
        },istudy:{
            name : '',
            text: "我的课程",
            icon: "http://img11.360buyimg.com/ddimg/jfs/t1/98808/33/12332/15690/5e464009E3400ee81/a7e881c1392046e7.png",
            isshow: 0,
            url: "/zofui_sales/study/order",
            type: "url",
            num: 0
        },mkefu:{
            name : '',
            text: "消息中心",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t1/62676/10/1699/4869/5cff5a7aE31581feb/7d78513324914e2b.png",
            isshow: 1,
            url: "/zofui_sales/kefu/list?role=user",
            type: "url",
            num: 0
        },help:{
            name : '',
            text: "帮助中心",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t28648/210/1260950193/5282/a584fe78/5cdb6717Na677dc15.png",
            isshow: 1,
            url: "/zofui_sales/help/list",
            type: "url",
            num: 0
        },addorder:{
            name : '',
            text: "添加订单",
            icon: "http://img12.360buyimg.com/ddimg/jfs/t1/110374/33/16925/6988/5eb66c68Efca6b5e4/f882410c4e8bd96b.png",
            isshow: 0,
            url: "/zofui_sales/adminb/addorder",
            type: "url",
            num: 0
        },live:{
            name : '',
            text: "直播Live",
            icon: "http://ddcdn.jd.com/ddimg/jfs/t1/126508/27/3438/9950/5ed10946Ea596372f/80d52337f30da445.png",
            isshow: 0,
            url: "/zofui_sales/live/mylive",
            type: "url",
            num: 0
        },kabao:{
            name : '',
            text: "我的卡包",
            icon: "http://ddcdn.jd.com/ddimg/jfs/t1/116233/11/10235/6851/5eea0e94Ec5b3c995/066ea56a248decba.png",
            isshow: 0,
            url: "/zofui_sales/kabao/list?type=1",
            type: "url",
            num: 0
        },about:{
            name : '',
            text: "关于我们",
            icon: "https://img11.360buyimg.com/ddimg/jfs/t10816/312/2969828373/5095/6968203e/5cdb6772Nd04a495f.png",
            isshow: 1,
            url: "/zofui_sales/about/index",
            type: "url",
            num: 0
        },kefu:{
            name : '',
            text: "官方客服",
            icon: "https://ui.fhcloudapi.cn/xcx_urm/img/my-kefu.png",
            isshow: 1,
            type: "kefu",
            num: 0
        }},
        isIPX : app.globalData.isIPX,
        showuserbtn : false,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        Time : app.globalData.Time,
        shopid : 0,
    },
    onShow: function () {
        wx.hideTabBar();
        if(this.data.inited) {
            this.onLoad(this.data.options);
            if( app.globalData.shopid > 0 && app.globalData.shopnav == 1 && app.globalData.shopunav != 1 ){
                app.com.setBar(app,this,app.globalData.shopid);
            }
        }
    },
    onLoad:function(options){
        var self = this;

        self.setData({
            options : options,
            zfid : options.zfid ? options.zfid : ( options.scene ? options.scene : 0 )
        });

        var shopid = app.globalData.shopid ? app.globalData.shopid : 0;
        var isposter = options.scene  ? 1 : 0;
        isposter = options.isposter*1 == 1 ? 1 : isposter;

        var postdata = {
            op:'info',
            zfid:self.data.zfid,
            isposter:isposter,
            shopid:shopid
        };

        app.com.getLocation(self,function(loc){
            postdata.lng = loc.longitude;
            postdata.lat = loc.latitude;
            app.com.auth(function(user){
                app.com.http('user_v1','POST',postdata,0,false,'','',function(res){
                    if (!res.data.errno && res.data) {

                        self.setData({
                            inited : true,
                            userinfo : res.data.data.userinfo,
                        })
                        setTimeout(function(){
                            self.setData({
                                Pagetheme : res.data.data.params.style,
                                params : res.data.data.params,
                                shopid : shopid > 0 && res.data.data.params.shopnav == 1 && res.data.data.params.shopunav == 0 ? shopid : 0,
                                sharedata : res.data.data.sharedata,
                                newuserlist : res.data.data.newuserlist ? res.data.data.newuserlist : [],
                                num : res.data.data.num,
                                'order[1].text' : res.data.data.params.payedn,
                                'func.card.isshow' : res.data.data.params.pucard == 1 ? 0 : 1,
                                'func.cut.isshow' : res.data.data.params.pucut == 1 ? 0 : 1,
                                'func.group.isshow' : res.data.data.params.pugroup == 1 ? 0 : 1,
                                'func.group.text' : '拼单'+res.data.data.params.goodbname,

                                'func.share.isshow' : res.data.data.params.pushare == 1 || res.data.data.params.isshowfx == 0 || res.data.data.params.fxlevel == 3 ? 0 : 1,
                                'func.share.text' : res.data.data.params.myfxbn,

                                'func.redbag.isshow' : res.data.data.params.pured == 1 ? 0 : 1,
                                'func.shop.isshow' : res.data.data.params.pushop == 1 ? 0 : 1,
                                'func.jifen.isshow' : res.data.data.params.pujfzx == 0 ? 1 : 0,
                                'func.jifen.text' : res.data.data.params.jfbname+'中心',

                                'func.agent.isshow' : res.data.data.params.isagent == 0 ? 1 : 0,
                                'func.agent.text' : res.data.data.params.agentname+'中心',
                                'func.fenc.isshow' : res.data.data.params.isgwtc == 1 ? 1 : 0,
                                'func.cityl.isshow' : res.data.data.params.isctdl == 1 ? 1 : 0,
                                'func.sign.isshow' : res.data.data.params.issign == 0 ? 1 : 0,
                                'func.help.isshow' : res.data.data.params.uhelp == 33 ? 1 : 0,
                                'func.about.isshow' : res.data.data.params.uabout == 22 ? 1 : 0,
                                'func.jizi.isshow' : res.data.data.params.isjizi == 1 ? 1 : 0,
                                'func.mkefu.isshow' : res.data.data.params.ucmess == 1 ? 1 : 0,
                                'func.collect.isshow' : res.data.data.params.iscollect == 0 ? 1 : 0,
                                'func.yhm.isshow' : res.data.data.params.isyhm == 2 ? 1 : 0,
                                'func.kefu.isshow' : res.data.data.params.ukefu*1 > 0 ? 1 : 0,
                                'func.daysign.isshow' : res.data.data.params.daysign*1 == 1 ? 1 : 0,
                                'func.istudy.isshow' : res.data.data.params.istudy*1 == 13 ? 1 : 0,
                                'func.addorder.isshow' : res.data.data.params.addorder*1 == 1 ? 1 : 0,
                                'func.live.isshow' : res.data.data.params.fsafwf*1 == 1123 ? 1 : 0,
                                'func.kabao.isshow' : res.data.data.params.udkb*1 == 1 ? 1 : 0,
                                
                                'func.quest.isshow' : res.data.data.params.isquest*1 == 1 ? 1 : 0,
                                'func.ctyagent.isshow' : res.data.data.params.ctyagent*1 == 52 ? 1 : 0,
                                'func.ctyagent.text' : res.data.data.params.ctybname,
                                page : res.data.data.params.pagetype == 1 ? res.data.data.page : '',

                            });
                            
                            wx.setNavigationBarTitle({
                              title:  res.data.data.params.title ? res.data.data.params.title : '我的',
                            });
                            if( res.data.data.params.bg ){
                                var color = res.data.data.params.bg;
                            }else{
                                var color = app.com.mainColor(res.data.data.params.style);
                            }
                            wx.setBackgroundColor({
                                backgroundColor : color
                            })

                            wx.setNavigationBarColor({
                                frontColor: '#ffffff',
                                backgroundColor: color,
                            });
                        },5);
                    }
                });
                var ushopid = app.globalData.shopunav == 1 ? 0 : shopid;
                app.com.setBar(app,self,ushopid);
            });
        })
        
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: self.data.sharedata.path,
            imageUrl : self.data.sharedata.img,
        }
    },
    onShareTimeline(){
        return {
            title: this.data.sharedata.title,
            query: this.data.sharedata.query,
            imageUrl : this.data.sharedata.img,
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.setData({
            isdown : true,
        });
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        var self = this;
        if( self.data.params.usermes == 1 || !wx.requestSubscribeMessage ){
            app.com.navigateto( e );
        }else{
            wx.requestSubscribeMessage({
                tmplIds : self.data.params.submess,
                complete : function(){
                    app.com.navigateto( e );
                }
            })
        }
    },
    redirectto : function( e ){
        var self = this;
        if( self.data.params.usermes == 1 || !wx.requestSubscribeMessage ){
            app.com.redirectto( e );
        }else{
            wx.requestSubscribeMessage({
                tmplIds : self.data.params.submess,
                complete : function(){
                    app.com.redirectto( e );
                }
            })
        }
    },  
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        var self = this;
        if( self.data.params.usermes == 1 || !wx.requestSubscribeMessage ){
            wx.switchTab({
              url: url
            })
        }else{
            wx.requestSubscribeMessage({
                tmplIds : self.data.params.submess,
                complete : function(){
                    wx.switchTab({
                      url: url
                    })
                }
            })
        }

    },
    callphone : function(e){
        app.com.callphone( e );
    },
    copy : function(e){
        app.com.copy( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    loginu(){
        this.setData({
            showuserbtn : true,
        })
        console.log('1')
        this.selectComponent('#authbtn').hideauth();      
    },
    authed(e){
        this.setData({
            showuserbtn:false,
            'userinfo.nickname' : e.detail.nickname,
            'userinfo.headimg' : e.detail.headimg,
        });
    },
    getPhoneNumber( e ){
        var self = this;
        if( e.type == 'bindtel' ){
            e = e.detail;
        }
        if( e.detail.errMsg == 'getPhoneNumber:ok') {
            var postdata = {
                iv: e.detail.iv,
                encryptedData: e.detail.encryptedData,
                op : 'encrypt'
            };
            app.com.http('user_v1','POST',postdata,0,true,'','',function(res){
                if (!res.data.errno) {
                    app.com.toast('已绑定','none');
                    self.setData({
                        'userinfo.account' : res.data.data,
                    });
                    var bindtel = self.selectComponent('#bindtel');
                    if(bindtel) bindtel.hidebind();
                }else{
                    app.com.alert(res.data.message);
                }
            });
        }else{
            app.com.alert('请允许授权'+e.detail.errMsg);
        }
        self.subMess();
    },
    mess(){
        var self = this;
        self.subMess();
    },
    subMess(){
        var self = this;
        if(wx.requestSubscribeMessage){
            wx.requestSubscribeMessage({
                tmplIds : self.data.params.submess,
                complete : function(){
                    
                }
            })
        }       
    },
    bindparent(){
        this.selectComponent("#bindparent").showfn();
    },
    subbindparent(e){
        var self = this;
        if(!e.detail){
            app.com.toast('请输入邀请码');
            self.selectComponent("#bindparent").showfn();
            return false;
        }
        var postdata = {
            pcode: e.detail,
            op : 'bindparent'
        };
        app.com.http('user_v1','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno) {
                app.com.toast('已绑定');
                
                self.setData({
                    'userinfo.parent' : res.data.data.parentid
                })
            }else{
                app.com.alert(res.data.message);
                self.selectComponent("#bindparent").showfn();
            }
        });
    },
}))